const { db } = require('../config')
const { command } = require('../config')
const _ = command
const { obd_collection } = require('../config')
exports.main = async (event, context) => {
    console.log(event)
    const userInfo = event.userInfo;
    // const collection = '1order_list';
    const condition = event.data;
    const region = userInfo.region;
    const grid = userInfo.grid;
    const name = userInfo.name;
    const newSign = condition.sign;
    let IDs = condition.IDs;
    if (IDs) {
        IDs = IDs.split(',')
    } else {
        return 0
    }
    if (!grid || !region) {
        console.log('没有网格区域')
        return { total: 0, data: [], page, pageSize };
    }
    let newName = !!newSign ? `${userInfo.name}` : '';
    let newAccount = !!newSign ? `${userInfo.account}` : '';

    let _condi = { region, grid:_.in(['',grid]), ID: _.in(IDs), staff: newSign ? _.eq('') : new RegExp(name) }
    console.log(condition)

    const res = await db.collection(obd_collection)
        .where(_condi)
        // .get()
        .update({
            staff: newAccount,
            staffName:newName,
            grid: grid
        });

    console.log('查询结果', res)
    return res.updated;

}